<template>
  <div id="shop">
    <div class="title">
      <a @click="toList"><<返回列表</a>
    </div>
    <div class="search">
      <el-form
        ref="form"
        :model="form"
        :inline="true"
        style="padding: 20px 20px 0 20px"
      >
        <el-form-item label="用户ID">
          <el-input
            v-model="form.uid"
            placeholder="用户ID"
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户手机号">
          <el-input
            v-model="form.tel"
            placeholder="用户手机号"
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <el-form-item label="区域">
          <el-select v-model="form.areaId" placeholder="请选择区域">
            <el-option
              v-for="v in area"
              :key="v.id"
              :label="v.name"
              :value="v.name"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="渠道">
          <el-select v-model="form.way" placeholder="全部" style="width: 150px">
            <el-option label="购买" value="1"></el-option>
            <el-option label="兑换码" value="2"></el-option>
            <el-option label="时长兑换" value="3"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div>
        <el-button type="info" style="margin-right: 10px" @click="search"
          >查询
        </el-button>
        <el-button type="info" style="margin-right: 100px" @click="rest"
          >重置
        </el-button>
      </div>
    </div>
    <!--表格  -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
    >
      <el-table-column prop="uid" label="ID" align="center"> </el-table-column>
      <el-table-column prop="tel" label="手机号" align="center"> </el-table-column>
      <el-table-column prop="aname" label="区域" align="center"> </el-table-column>
      <el-table-column prop="cname" label="名称" align="center"> </el-table-column>
      <el-table-column prop="buyTime" label="卡券获得时间" width="180px" align="center">
      </el-table-column>
      <el-table-column prop="expireTime" label="卡券过期时间" width="180px" align="center">
      </el-table-column>
      <el-table-column prop="channel" label="卡券获取渠道" align="center">
        <template slot-scope="scope">{{
          scope.row.channel == 1
            ? "购买"
            : scope.row.channel == 2
            ? "兑换码"
            : scope.row.channel == 3
            ? "时长兑换"
            : "无法查看"
        }}</template>
      </el-table-column>
      <el-table-column prop="price" label="价格" align="center"> 
           <template slot-scope="scope">{{ scope.row.price + "/h" }}</template >
      </el-table-column>
    </el-table>
    <div class="page">
      <el-pagination
        style="float: right"
        @current-change="handleCurrentChange"
        :current-page.sync="page"
        :page-size="limit"
        layout="prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: [],
      form: {
        areaId: "",
        uid: "",
        tel: "",
        way: "",
      },
      input: "",
      //分页
      page: 1,
      limit: 5,
      total: 50,
      area: [],
    };
  },
  methods: {
    handleCurrentChange: function (val) {
      this.page = val;
      this.getData();
    },
    //渲染
    getData: function () {
      this.$axios({
        url: "/coupon/purchase/list",
        method: "post",
        data: {
          page: this.page,
          limit: this.limit,
          uid: this.form.uid,
          tel: this.form.tel,
          channel: this.form.way,
          aname: this.form.areaId,
        },
      }).then(({ data }) => {
        console.log(data);
        this.tableData = data.data.purchase;
        this.total = data.data.count;
      });
    },
    //获取区域下拉
    toArea: function () {
      this.$axios({
        url: "/area/queryall",
      }).then(({ data }) => {
        this.area = data.data;
      });
    },
    //查询
    search: function () {
      this.getData();
    },
    //重置
    rest: function () {
      this.form.areaId = "";
      this.form.uid = "";
      this.form.tel = "";
      this.form.way = "";
      this.getData();
    },
    toList:function(){
      this.$router.push("/home/CardMange")
    }
  },
  mounted: function () {
    this.getData();
    this.toArea();
  },
};
</script>
<style lang="less" scoped>
#shop {
  padding: 0;
  text-align: left;
  line-height: 0;
  .title {
    height: 40px;
    display: flex;
    justify-content: space-between;
    a {
      color: #02a7f0;
      font-weight: bold;
      cursor: pointer;
    }
  }
  .search {
    margin-top: 10px;
    width: 100%;
    background: #d7d7d7;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
</style>
